$(function() {
  var myFav = new Vue({
    el:"#cardBody",
    data:{
      payHospitals:[],
      payDoctors:[]
    },
    methods:{
      getPayHospital:function () {
        var that = this;
        axios.get("../api/user/getPayHospital",
            {headers:{'token':localStorage.getItem('token')}}).then(function(response){
          console.log(response)
          if (response.data.code!="0"){
            alert(response.data.msg);
            return
          }
          console.log(response.data.data.list)
          that.payHospitals = response.data.data.list;
        }).catch(function(err){
          console.log(err);
        });
      },
      getPayDoctor:function(){
        var that = this;
        axios.get("../api/user/getPayDoctor",
            {headers:{'token':localStorage.getItem('token')}}).then(function(response){
          console.log(response)
          if (response.data.code!="0"){
            alert(response.data.msg);
            return
          }
          console.log(response.data.data.list)
          that.payDoctors = response.data.data.list;
        }).catch(function(err){
          console.log(err);
        });
      },
      unPayDoctor:function (data) {
        axios.get("../api/doctor/unPayDoctor?doctorId="+data,
            {headers:{'token':localStorage.getItem('token')}}).then(function(response){
          console.log(response)
          if (response.data.code!="0"){
            alert(response.data.msg)
            return
          }
          location.href="user_info.html";
        }).catch(function(err){
          console.log(err);
        });
      },
      unPayHospital:function (data) {
        axios.get("../api/back/unPayHospital?HospitalId="+data,
            {headers:{'token':localStorage.getItem('token')}}).then(function(response){
          console.log(response)
          if (response.data.code!="0"){
            alert(response.data.msg)
            return;
          }
          location.href="user_info.html";
        }).catch(function(err){
          console.log(err);
        });
      }
    },
    created(){
      this.getPayHospital();
      this.getPayDoctor();
    }
  })

  var getTokenVue = new Vue({
    el:"#getToken",
    data:{
      token:localStorage.getItem("token")
    }
    ,methods:{

    }
  })

  $(document).on('click', '.hos-btn', handleHosBtnClick);
  $(document).on('click', '.doc-btn', handleDocBtnClick);

  function handleHosBtnClick() {
    window.open('hospital.html?hospital=' + $(this).data('id'));
  }

  function handleDocBtnClick() {
    window.open('doctor.html?doctor=' + $(this).data('id'));
  }
})